﻿/*
 * Copyright (C) 2012, Jesus Requejo <jesus.requejo@gmail.com> 
 * Licensed under Microsoft Public License (Ms-PL)
 * http://www.microsoft.com/en-us/openness/licenses.aspx#MPL
*/

namespace LoaderServiceManager {

   using System.Windows.Forms;
   using System.IO;
   
   public partial class AddOrEditApplication : Form {
      public AddOrEditApplication() {
         InitializeComponent();
      }

      public string AppName {
         set { nameTextBox.Text = value; }
         get { return this.nameTextBox.Text; }
      }

      public string AppPath {
         set { pathTextBox.Text = value; }
         get { return this.pathTextBox.Text; }
      }

      public bool AppEnabled {
         set { enabledCheckBox.Checked = value; }
         get { return this.enabledCheckBox.Checked; }
      }

      private void browseLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
         string initialDirectory = CalculateInitialDirectory(AppPath);         
         var path = Common.GetApplicationPathFromOpenFileDialog(initialDirectory);
         if (!string.IsNullOrWhiteSpace(path)) {
            pathTextBox.Text = path;
         }
      }

      private string CalculateInitialDirectory(string appPathText) {
         if (string.IsNullOrWhiteSpace(appPathText)) {
            return null;
         }
         var directoryName = Path.GetDirectoryName(AppPath);
         return string.IsNullOrWhiteSpace(directoryName) ? null : System.IO.Path.GetDirectoryName(appPathText);
      }

      internal void HideEnabledCheckBox() {
         this.enabledCheckBox.Visible = false;
      }

      internal void SetGroupBoxText(string text) {
         groupBox1.Text = text;
      }
   }
}
